const Validate = {
  mobile: function (num) { // 验证手机
    return /^1[3|4|5|7|8][0-9]\d{8}$/.test(num)
  }
}
Page({
  data: {
    phone: '13619604534',
    info: {
      deviceId: 'test',
      username: '',
      password: '',
      mobile: '',
      wechatId: '',
      sms:'',
      comfire: '',
    }
  },
  submit () {
    const self = this
    let params = {
      deviceId: this.info.deviceId, 
      username: this.info.username, 
      mobile: this.info.mobile, 
      sms: this.info.sms, 
      pwd: this.info.password, 
      wechatId: this.info.wechatId
    }
    self.$api.user.forgetPwd(params).then(res => {
      if(res.code>0){
        self.$router.push('/login')
      }else{
        self.$Toast(res.msg)
      }
    })
  },
  sendsms () {
    const self = this
    if (!Validate.mobile(self.info.mobile)) {
      self.$Toast('请填写正确的手机号码')
      return
    }
    self.$api.user.sendSms({mobile: self.info.mobile}).then(res => {
      if(res.code > 0){
        self.$Toast('验证码发送成功')
      } else {
        self.$Toast(res.msg)
      }
    })
  }
})